package com.lyc.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;
import java.util.Arrays;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${upload.path}")
    private String uploadPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String path = uploadPath.replace("\\", "/");
        if (!path.endsWith("/")) {
            path += "/";
        }

        String fileLocation = "file:" + path;

        registry.addResourceHandler("/uploads/**")
                .addResourceLocations(fileLocation);
    }
}

